home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: miker3@ix.netcom.com (Mike Rubenstein)
- Newsgroups: comp.lang.c++,comp.lang.c
- Subject: Re: Hungarian notation
- Date: Wed, 17 Jan 1996 19:55:54 GMT
- Organization: Netcom
- Message-ID: <30fd5306.3171520@nntp.ix.netcom.com>
- References: <4dhkae$an9@blackice.winternet.com> <821890870snz@genesis.demon.co.uk>
- NNTP-Posting-Host: ix-dc15-24.ix.netcom.com
- X-NETCOM-Date: Wed Jan 17 11:55:54 AM PST 1996
- X-Newsreader: Forte Agent .99c/16.141
-
- Lawrence Kirby <fred@genesis.demon.co.uk> wrote:
-
- |>In article <4dhkae$an9@blackice.winternet.com>
- |> jdege@winternet.com "Jeff Dege" writes:
- |>
- |>> Generally speaking, when I use printf(), et al., with integer
- types
- |>>of uncertain or unknown size, I explicitly cast. i.e.:
- |>>
- |>>printf("The current epoch is %ld\n", (long) time(NULL));
- |>>
- |>> This is, as far as I know, the only safe way to printf() a
- time_t,
- |>>size_t, etc.
- |>
- |>There is no guarantee that time_t is an integer. To print it safely
- you
- |>should cast it to long double. size_t is guaranteed to be an
- unsigned
- |>integer so it should be cast to unsigned long for printing.
-
- I'm sure Lawrence is aware of this, but it's worth noting that while
- casting to long double is almost certainly safe in that it will not
- cause damage, it may not print out anything useful. It's possible
- that time_t is an integral type that cannot be represented exactly as
- a long double and the least significant bits, that are lost in the
- conversion, may be significant.
-
- There is one possibility that makes the cast to long double
- potentially dangerous according to the standard. There is no
- guarantee in the standard that all possible values of an integral type
- can be converted to long double. Such an implementation would be
- pretty wierd, and I doubt if we'll ever see one.
-
-
- Michael M Rubenstein
-